import { ResPage, User, Login, Role } from "@/api/interface/index";
import { PORT1 } from "@/api/config/servicePort";
import http from "@/api";
import { ReqParams } from "@/interface/public";

/**
 * @name 用户管理模块
 */
// 获取用户列表
export const getUserList = (params: User.ReqUserParams) => {
  return http.post<ResPage<User.ResUserList>>(PORT1 + `/user/pageByStatus`, params);
};

// 新增用户
export const userSave = (params: User.ResUserList) => {
  return http.post(PORT1 + `/user/save`, params);
};

// 管理员修改用户密码
export const userUpPasswordByAdmin = (params: Login.ReqLoginForm) => {
  return http.post(PORT1 + `/user/upPasswordByAdmin`, params);
};

// 用户修改密码
export const userUpPasswordByUser = (params: User.ReqChangePassword) => {
  return http.post(PORT1 + `/user/upPasswordByUser`, params);
};

// 启用/禁用 用户
export const userUpStatus = (params: ReqParams) => {
  return http.post(PORT1 + `/user/upStatus`, params);
};

// 角色列表
export const roleList = () => http.get<Role.ResRoleList>(PORT1 + `/role/list`);

// 角色新增
export const roleSave = (params: Role.ReqSave) => http.post(PORT1 + `/role/save`, params);

// 角色删除
export const roleRemove = (params: ReqParams) => http.post(PORT1 + `/role/remove`, params);

// 编辑角色内用户
export const roleUserSave = (params: Role.ReqEdit) => http.post(PORT1 + `/roleUser/save`, params);

// 所有用户
export const userPageByStatus = (params: { key: string }) => {
  const data = {
    status: 0,
    key: params.key,
    pageNum: 1,
    pageSize: 100
  };
  return http.post(PORT1 + `/user/pageByStatus`, data);
};

// 获取权限列表
export const roleMenuGetByRoleId = (params: { roleId: number }) => http.get(PORT1 + `/roleMenu/getByRoleId`, params);

// 保存权限列表
export const roleMenuSave = (params: Role.ReqRoleMenuSave) => http.post(PORT1 + `/roleMenu/save`, params);
